package com.allo2o.common.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.allo2o.common.domain.SysUserDO;
import com.allo2o.common.mapper.SysUserDOMapper;
import com.allo2o.common.service.ISysUserService;
import com.allo2o.exception.CheckedException;
import com.allo2o.shared.util.AESUtil;
import com.allo2o.shared.util.StringUtil;

@Service
public class SysUserServiceImpl implements ISysUserService {
	@Autowired
	private SysUserDOMapper sysUserDOMapper;

	@Override
	public SysUserDO login(SysUserDO sysUser) throws CheckedException {
		sysUser.setPassword(AESUtil.encrypt(sysUser.getPassword())); // 将密码加密
		System.out.println(sysUser.getPassword());
		SysUserDO sysUserDO = sysUserDOMapper.login(sysUser);
		if (StringUtil.isNull(sysUserDO)) {
			throw new CheckedException("账号或密码错误！");
		}
		sysUserDO.setPassword(null);//密码付空
		return sysUserDO;
	}

}